<template>
  <div>
    <el-dialog title="详细信息" :visible.sync="UserInfodialogTableVisible">
        <el-descriptions class="margin-top" :column="2" border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              姓名
            </template>
            {{ formLabelAlign.adminName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              性别
            </template>
            {{ formLabelAlign?.adminSex == 1 ? '男' : '女' }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              工号
            </template>
            {{ formLabelAlign.adminNum }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              校区
            </template>
            {{ formLabelAlign?.adminAddress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-tickets"></i>
              职位
            </template>
            {{ formLabelAlign?.adminProfession }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              电话
            </template>
            {{formLabelAlign?.adminPhone }}

          </el-descriptions-item>
               <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              工作状态
            </template>
            <span v-if="formLabelAlign.adminWorkStatus == 0">空闲</span>
            <span v-if="formLabelAlign.adminWorkStatus == 1">忙碌</span>
            <span v-if="formLabelAlign.adminWorkStatus == 2">离职</span>
     
          </el-descriptions-item>
        </el-descriptions>
     
          <!-- <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              初访老师
            </template>
            {{ initiaByone.visitTeacher }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              问卷评分
            </template>
            {{ initiaByone.visitCrisisGrades }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              详细描述
            </template>
            {{ initiaByone.userCrisisText }}
          </el-descriptions-item>
        </el-descriptions> -->
        <div slot="footer" class="dialog-footer">
          <el-button @click="UserInfodialogTableVisible = false">确定</el-button>
          <!-- <el-button type="primary">审核</el-button> -->
        </div>
      </el-dialog>



<!-- 
  <el-dialog
     title="详细信息"
    :visible.sync="UserInfodialogTableVisible"
    class="dialog"
    >
<div  class="left">
  <el-form :label-position="labelPosition" label-width="90px"  :model="formLabelAlign" disabled >
  <el-form-item label="ID">
    <el-input v-model="formLabelAlign.adminId" ></el-input>
  </el-form-item>
  <el-form-item label="工号">
    <el-input v-model="formLabelAlign.adminNum"></el-input>
  </el-form-item>
  <el-form-item label="姓名" >
    <el-input v-model="formLabelAlign.adminAge"></el-input>
  </el-form-item>
  <el-form-item label="性别">
    <el-input  v-model="adminSex">
    </el-input>
  </el-form-item>
  <el-form-item label="所在校区">
    <el-input v-model="formLabelAlign.adminAddress"></el-input>
  </el-form-item>
  <el-form-item label="学生专业">
    <el-input v-model="formLabelAlign.adminProfession"></el-input>
  </el-form-item>
  <el-form-item label="工作状态">
    <el-input v-model="formLabelAlign.adminWorkStatus"></el-input>
  </el-form-item>
  <el-form-item label="学生手机号">
    <el-input v-model="formLabelAlign.adminPhone"></el-input>
  </el-form-item>
  <el-form-item label="学生密码">
    <el-input v-model="formLabelAlign.adminPassword"></el-input>
  </el-form-item>
   <el-form-item label="创建时间">
    <el-input v-model="formLabelAlign.createTime"></el-input>
  </el-form-item>
  <el-form-item label="更新时间">
    <el-input v-model="formLabelAlign.updateTime"></el-input>
  </el-form-item>
</el-form>
</div>
</el-dialog> -->
  <div style="margin: 15px 0;"></div>
    <!-- 面包屑导航区域 -->
    <!-- <BRED></BRED> -->
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
       <!-- Admin详细信息 -->

      <!-- 搜索与添加区域 -->
      <!-- Layout布局 - > 混合布局
             :gutter="20" 两个格子之间的间隔
          -->
      <el-row :gutter="10">
        <el-col :span="7">
          <!-- Input输入框 - > 复合型输入框 -->
          <el-input
            placeholder="输入Admin名/职位/工号/校区查询"
            v-model='select'
           
            @keyup.enter.native="SelectUser"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="SelectUser"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="dialogVisible = true"
            >添加Admin</el-button
          >
        </el-col>
        <el-col :span="5">   <el-dropdown>
          <el-button type="primary" style="margin-left: 580px">
            操作<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              @click.native="dropdown(item)"
              v-for="(item, index) in drowStatus"
              :key="index"
              >{{ item.lable }}</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown></el-col>
        <el-col :span="7"> <el-button type="primary" class="el-icon-refresh-left"

          @click="refresh"
           style="margin-left: 370px"></el-button></el-col>

      </el-row>
   
      <el-table
        :data="sysUserList"
        border
        style="width: 100%"
        ref="multipleTable"
        @select="onTableSelect"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          :selectable="selectable"
          align="center"
          type="selection"
          width="60px"
      
        >
        </el-table-column>

        <el-table-column prop="adminId" label="id" width="50" align="center"></el-table-column>
        <el-table-column
        align="center"
          prop="adminNum"
          label="工号"
          width="100px"
         
        ></el-table-column>
        <el-table-column
        align="center"
         width="120px"
          prop="adminProfession"
          label="职位"
      
        ></el-table-column>
        <el-table-column
        align="center"
         width="120px"
          prop="adminName"
          label="姓名"
      
        ></el-table-column>
        <el-table-column
         align="center"
          prop="adminAge"
          label="年龄"
          v-if="false"
        ></el-table-column>
        <el-table-column prop="adminSex" label="性别" width="90px"  align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.adminSex == 1">男</span>
            <span v-if="scope.row.adminSex == 0">女</span>
          </template>
        </el-table-column>
            <el-table-column prop="adminAddress" label="所在校区" width="120px"  align="center"></el-table-column>
         <el-table-column prop="adminWorkStatus" label="工作状态" width="80px"  align="center">
            <template slot-scope="scope">
            <span v-if="scope.row.adminWorkStatus == 0">空闲</span>
            <span v-if="scope.row.adminWorkStatus == 1">忙碌</span>
            <span v-if="scope.row.adminWorkStatus == 2">离职</span>
          </template>
         </el-table-column>
        <el-table-column prop="adminPhone" label="电话" width="140px"  align="center"> </el-table-column>
        <el-table-column prop="adminPassword" label="密码" width="140px"  align="center"> </el-table-column>
        <el-table-column prop="create_date" label="创建时间" width="160px" align="center">
          <template slot-scope="scope">
            {{ $formatDate(scope.row.create_date) }}
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="160px" align="center">
          <template slot-scope="scope">
            {{ $formatDate(scope.row.updateTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="100px" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              :inactive-value="2"
              @change="sysUserStatusChange(scope.row)"
            >
            </el-switch>
          </template>
          <!-- <template slot-scope="scope">
              <el-switch
              v-model="scope.row.status"
               :active-value="1"
               :inactive-value="2"
               @change="sysUserStatusChange(scope.row)">
              </el-switch>
          </template> -->
        </el-table-column>
        <el-table-column label="操作" align="center" width="150px">
          <template slot-scope="scope">
            <!-- 修改 -->
           <el-tooltip content="修改"
            class="item"
              effect="dark"
              placement="top"
              :enterable="false"
           >
             <el-button
              type="primary"
              size="mini"
              @click="showEditDialog(scope.row)"
              icon="el-icon-edit"
              circle
            ></el-button>
           </el-tooltip>
            <!-- 删除 -->
           <el-tooltip
            class="item"
              effect="dark"
              placement="top"
                content="删除"
              :enterable="false">
            <el-button
              type="danger"
              size="mini"
              @click="removeSysUserById(scope.row.adminId)"
            :disabled="adminId==scope.row.adminId"
              icon="el-icon-delete"
              circle
            ></el-button>
              </el-tooltip>
            <!-- 分配角色 :enterable 作用域插槽 -->
            <el-tooltip
              class="item"
              effect="dark"
              content="详细信息"
              placement="top"
              :enterable="false"
            >

              <el-button
              @click="showSysUserById(scope.row)"
                type="success"
                size="mini"
                icon="el-icon-more-outline"
                circle
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChangeFn"
        @current-change="handleCurrentChangeFn"
        :current-page.sync="q.pagenum"
        :page-sizes="[2, 3, 5, 10]"
        :page-size.sync="q.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
      >
      </el-pagination>

      <!-- 添加Admin的对话框 -->
      <el-dialog
        title="添加Admin"
        :visible.sync="dialogVisible"
        @close="addDialogClose"
        width="40%"
      >


        <!-- 添加内容主题区域 ----------------------------------------------------------------------------------------------------------->
        <el-form
          :model="addForm"
          :rules="addFormRules"
          ref="addFormRef"
          label-width="100px"
        >
          <el-form-item label="工号" prop="adminNum"  >
            <el-input v-model="addForm.adminNum"  placeholder="！！！!注意每个职位工号有特殊规范！！！！" @change="getAdminNum" maxlength="3"></el-input>
          </el-form-item>
          <el-form-item label="姓名" prop="adminName">
            <el-input v-model="addForm.adminName"></el-input>
          </el-form-item>
           <el-form-item label="年龄" prop="adminAge">
            <el-input v-model="addForm.adminAge"></el-input>
          </el-form-item>
          <el-form-item label="Admin密码" prop="adminPassword">
            <el-input
              type="password"
              v-model="addForm.adminPassword"
              autocomplete="off"
            ></el-input>
          </el-form-item>

          <el-form-item label="确认密码" prop="checkPass">
            <el-input
              type="password"
              v-model="addForm.checkPass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          
           <el-form-item label="状态" prop="adminWorkStatus">
            <el-select v-model="addForm.adminWorkStatus" placeholder="请选择状态">
              <el-option label="空闲" value="0"></el-option>
              <el-option label="忙碌" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所在校区" prop="adminAddress">
            <el-select v-model="addForm.adminAddress" placeholder="请选择所在校区">
              <el-option label="自贡校区" value="自贡校区"></el-option>
              <el-option label="宜宾校区" value="宜宾校区"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="职位" prop="adminProfession">
            <el-select v-model="addForm.adminProfession" placeholder="请选择职位">
              <el-option label="中心管理员" value="中心管理员"></el-option>
                <el-option label="初访员" value="初访员"></el-option>
              <el-option label="咨询师" value="咨询师"></el-option>
             
                <el-option label="心理助理" value="心理助理"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="电话号码" prop="adminPhone">
            <el-input v-model="addForm.adminPhone" maxlength="11"></el-input>
          </el-form-item>
          <!-- <el-form-item label="邮箱地址" prop="email">
            <el-input v-model="addForm.email"></el-input>
          </el-form-item> -->
          <el-form-item label="选择性别" prop="adminSex">
            <el-radio-group v-model="addForm.adminSex">
              <el-radio label="1">男</el-radio>
              <el-radio label="0">女</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="备注" prop="remark">
            <el-input type="textarea" v-model="addForm.remark"></el-input>
          </el-form-item> -->
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitSysUser">确 定</el-button>
        </span>
      </el-dialog>





      <!-- 修改Admin的对话框    -------------------------------------------------------------------------------------------------------------->
      <el-dialog
        title="修改Admin"
        :visible.sync="editDialogVisible"
        @close="editDialogClose"
        width="40%"
      >
        <!-- 修改内容主题区域 -->
        <el-form
          :model="editForm"
          :rules="editFormRules"
          ref="editFormRef"
          label-width="100px"
        >
         <el-form-item label="Admin名称">
            <el-input v-model="editForm.adminName" ></el-input>
          </el-form-item>
           <el-form-item label="新密码" prop="adminPassword">
            <el-input v-model="editForm.adminPassword" ></el-input>
          </el-form-item>
        <el-form-item label="状态" prop="adminWorkStatus">
            <el-select v-model="editForm.adminWorkStatus" placeholder="请选择状态">
              <el-option label="空闲" value="空闲"></el-option>
              <el-option label="忙碌" value="忙碌"></el-option>
              <el-option label="离职" value="离职"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所在校区" prop="adminAddress">
            <el-select v-model="editForm.adminAddress" placeholder="请选择所在校区">
              <el-option label="自贡校区" value="自贡校区"></el-option>
              <el-option label="宜宾校区" value="宜宾校区"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="职位" prop="adminProfession">
            <el-select v-model="editForm.adminProfession" placeholder="请选择职位">
              <el-option label="中心管理员" value="中心管理员"></el-option>
              <el-option label="初访员" value="初访员"></el-option>
              <el-option label="咨询师" value="咨询师"></el-option>
                <el-option label="心理助理" value="心理助理"></el-option>
            </el-select>
          </el-form-item>
         <el-form-item label="新工号" prop="adminNum"  >
            <el-input v-model="editForm.adminNum" @change="getAdminNumEdit"></el-input>
          </el-form-item>
          <el-form-item label="电话号码" prop="adminPhone">
            <el-input v-model="editForm.adminPhone"></el-input>
          </el-form-item>
          <el-form-item label="选择性别">
            <el-radio-group v-model="editForm.adminSex">
              <el-radio :label="1">男</el-radio>
              <el-radio :label="0">女</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitEditSysUser">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import {
  getadmins,
  inituser,
  editAdmin,
  updateSysUserStatus,
  deleteAdminsApI,
  addAdminApI,
  deleteAdminByIdApI,
  findAdminByNameApI
} from '@/api/Admin/admin'
export default {
  name: 'Lo_',
  components: {
    BRED: () => import('@/components/BRED/index.vue')
  },
  data () {
    // 验证密码
    const valipwd = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        if (this.addForm.checkPass !== '') {
          this.$refs.addFormRef.validateField('checkPass')
        }
        callback()
      }
    }
    // 验证确认密码
    const valirepwd = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.addForm.adminPassword) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }

    return {
      relation: '',
      Distribution: [
        {
          id: 1,
          title: '管理员1'
        },
        {
          id: 2,
          title: '管理员2'
        },
        {
          id: 3,
          title: '管理员3'
        }
      ],
      labelPosition: 'right',
      adminSex:'',
      formLabelAlign: {
        adminId:'',
        adminNum:'',
        adminName: '',
        adminAge: '',
        adminSex: '',
        adminAddress: '',
        adminProfession: '',
       adminWorkStatus:'',
       adminPhone:'',
       adminPassword:'',
       createTime:'',
       updateTime:''
      },
      select: '',
      drowStatus: [
        { lable: '删除', value: 1 },
        { lable: '冻结', value: 2 }
      ],

      // 默认的条件
      q: {
        pagenum: 1,
        pagesize: 2,
        cate: '1',
        state: '1'
      },
      sysUserList: [],
      ids: [],
      totalSize: 5,
      // 对话框
      dialogVisible: false,
      // 添加Admin表单数据
      addForm: {
        adminNum:'',
        adminName: '',
        adminAge: '',
        adminSex: '0',
        adminAddress: '自贡校区',
        adminProfession: '中心管理员',
       adminWorkStatus:'空闲',
       adminPhone:'',
       adminPassword:'',
        checkPass: '',
        adminAccess:''
      },
      // Admin表单验证规则
      addFormRules: {
        adminPhone: [
          {
            pattern:
              /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '电话号码格式不对',
            trigger: 'blur'
          },
          { required: true, message: '请输入电话号码', trigger: 'blur' }
        ],
        adminName: [
          { required: true, message: '请输入Admin名', trigger: 'blur' },
          {
            min: 2,
            max: 15,
            message: 'Admin名称长度在 2 到 15 个字符',
            trigger: 'blur'
          }
        ],
        adminAge: [
          {
            pattern:
               /^(?:[1-9][0-9]?|1[01][0-9]|120)$/,
            message: '年龄无效',
            trigger: 'blur'
          },
          { required: true, message: '请输入年龄', trigger: 'blur' }
        ],
        adminNum:[
                    { required: true, message: '请输入工号', trigger: 'blur' }
        ],
        adminPassword: [{ required: true, validator: valipwd, trigger: 'blur' }],
        checkPass: [{ required: true, validator: valirepwd, trigger: 'blur' }],
      },
      editid: [],
      // 控制修改对话框演示与隐藏
      editDialogVisible: false,
      UserInfodialogTableVisible: false,
      DistributeTableVisible: false,
      // 定义只负责接收编辑查询信息
      editForm: {
        adminNum:'',
        adminName: '',
        adminAge: '',
        adminSex: '',
        adminAddress: '',
        adminProfession: '',
       adminWorkStatus:'',
       adminPhone:'',
       adminPassword:'',
        checkPassA: '',
        adminAccess:''
      },
      updataUser: {},
      re: true,
      FirstNum:'',
      FirstNumEdit:'',
      is_true:'false',
      is_trueEdit:'true',
      // Admin表单验证规则
      editFormRules: {
         adminNum:[
                    { required: true, message: '请输入工号', trigger: 'blur' }
        ],
          adminPassword: [{ required: true, trigger: 'blur' }],
          // checkPassA: [{ required: true, validator: valirepwd1, trigger: 'blur' }],
        adminPhone: [
          {
            pattern:
              /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '电话号码格式不对',
            trigger: 'blur'
          },
          { required: true, message: '请输入电话号码', trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {
    const url = window.location.href
    console.log(url)
    this.getSysUserList()
    this.initArticleList()
    try {
      // this.select = url.split('?')[1].split('=')[1]
      console.log('adwawd')
      this.initArticleList()
    } catch (error) {
      // console.log('dwadawdwadwaadwaadwaadwaadwaadwaadwa')
    //   this.getSysUserList()
      // this.initArticleList()
    }
    // if (url.split('?')[1] !== null || url.split('?')[1] !== '') {
    //   console.log('adwawd')
    //   this.select = url.split('?')[1].split('=')[1]
    //   this.SelectUser()
    // } else {
    //   console.log('dwadawdwadwaadwaadwaadwaadwaadwaadwa')
    //   this.getSysUserList()
    //   this.initArticleList()
    // }
  },
    computed: {
    adminNum() {
      return this.$store.state.adminInfo.adminNum || [];
    },
    adminName() {
      return this.$store.state.adminInfo.adminName || [];
    },
    adminId() {
      return this.$store.state.adminInfo.adminId || [];
    },
  },
  methods: {
    // 刷新
    refresh () {
      // location.href = 'http://localhost:8080/#/sysuser'
      this.select = ''
    //   this.getSysUserList()
    this.initArticleList()
    },
    // 拿到角色勾选的值
    handle () {

    },
    Distribute () {
      this.DistributeTableVisible = true
    },
    // 角色分配
    fengPei (val) {
      console.log(val.map(item => item.id))
    },
    onSubmitDistribute () {
      console.log(this.relation)
      this.DistributeTableVisible = false
    },
    // 展示Admin详细信息
    showSysUserById (e) {
      this.UserInfodialogTableVisible = true
      if(this.formLabelAlign.adminSex==0){
        this.adminSex='男'
      }
      else{
         this.adminSex='女'
      }
      this.formLabelAlign = e
      this.formLabelAlign.createTime=this.$formatDate(this.formLabelAlign.createTime)
      this.formLabelAlign.updateTime=this.$formatDate(this.formLabelAlign.updateTime)
    //   console.log('123', e)
    },
    // 查询
    async SelectUser () {
      console.log('se',this.select)
      const res = await findAdminByNameApI(this.select)
      console.log(123, this.select)
      console.log('user', res.data)
      if (res.data.code === 0) {
        console.log("231312",res.data.data)
        this.sysUserList= []
        this.sysUserList=res.data.data
         this.totalSize=res.data.data.length
        console.log("222",this.sysUserList)
      } else {
        this.$message.error('查询失败！！！')
      }
    },
    // 禁用id1
    selectable (row, index) {
      if (row.id === 1) {
        return false
      } else {
        return true
      }
    },
    geteditname (a, b) {
      // console.log('123', a, b)
    },
    getAdminNum(){
      console.log('7777',this.addForm.adminNum.charAt(0))
      this.FirstNum=this.addForm.adminNum.charAt(0)
    },
    getAdminNumEdit(){
    this.FirstNumEdit=this.editForm.adminNum.charAt(0)
      console.log("11111111",this.FirstNumEdit)
    },
    async getSysUserList () {
      const { data: res } = await getadmins()
      console.log(res.data)
      if (res.code !== 0) {
        this.$message.error('无法获取Admin数据列表')
      } else {
        // res.data.forEach((element, index) => {
        //   console.log(index, element)
        //   if (index < res.data.length - 1) {
        //     this.sysUserList[index] = element
        //   }
        // })
        // this.sysUserList = []
        // this.sysUserList=res.data
       this.totalSize=res.data.length
        // console.log('Admin列表', this.sysUserList)
  
      }
    },
    // 更新分页,信息
    async initArticleList () {
      this.select = ''
      const pagenum = this.q.pagenum-1
      const result = await inituser(pagenum*this.q.pagesize, this.q.pagesize)
      if (result.data.code === 0) {
        console.log('thisAdmin', result.data.data)
        this.sysUserList = result.data.data
        // this.totalSize=result.data.data.length+1
        // this.resetListFn()
        console.log('123222', result.data.data)
      }
    },
    handleSizeChangeFn (e) {
      this.pagesize = e
      this.q.pagenum = 1
      this.initArticleList()
      // this.resetListFn()
    },
    handleCurrentChangeFn (e) {
      this.pagenum = e
      this.initArticleList()
      // this.resetListFn()
    },
    // 重置
    resetListFn (forname) {
      this.q = {
        pagenum: 1,
        pagesize: 2,
        cate_id: '',
        state: ''
      }
      // 必须要有rule ref prop
      // this.$refs.pubFormRef.resetFields()
      this.initArticleList()
    },
    // 监听switch开关状态的改变
    async  sysUserStatusChange (sysUserInfo) {
      // console.log(sysUserInfo)
      // const res = await updateSysUserStatus(sysUserInfo.id, sysUserInfo.status)
      // if (res.data.code === 0) {
      //   this.$message.success('更新成功')
      //   this.getSysUserList()
      //   this.initArticleList()
      // } else {
      //   this.$message.error('更新失败')
      // }
      // console.log(res)
    },
    // 监听添加Admin关闭对话框的事件
    addDialogClose () {
      this.$refs.addFormRef.resetFields()
    },
    // 提交添加Admin
    submitSysUser () {
      this.addForm.adminPhone= parseInt(this.addForm.adminPhone);
      if(this.addForm.adminWorkStatus=='空闲'){
        this.addForm.adminWorkStatus=0;
      }
      else{
        this.addForm.adminWorkStatus=1;
      }
      if(this.addForm.adminProfession=='中心管理员'&&this.FirstNum=='1'){
        this.is_true=true
        this.addForm.adminAccess=1
      }
      else if(this.addForm.adminProfession=='初访员'&&this.FirstNum=='2'){
          this.is_true=true
        this.addForm.adminAccess=2
      }
      else if(this.addForm.adminProfession=='咨询师'&&this.FirstNum=='3'){
          this.is_true=true
        this.addForm.adminAccess=3
      }
      else if(this.addForm.adminProfession=='心理助理'&&this.FirstNum=='4'){
          this.is_true=true
        this.addForm.adminAccess=4
      }
      else{
      this.is_true=false
      }
      const { adminNum, adminName, adminAge, adminSex, adminAddress, adminProfession, adminWorkStatus ,adminPhone, adminPassword ,adminAccess} =
        this.addForm
      this.$refs.addFormRef.validate(async (valid) => {
        // console.log("123",this.FirstNum)
        // console.log(this.is_true)
        // console.log(this.FirstNum=='4')
        // console.log(this.FirstNum==4)
        if (valid&&this.is_true) {
          // 发起真正的提交
          const { data: res } = await addAdminApI(
           adminNum, 
           adminName, 
           adminAge, 
           adminSex, 
           adminAddress, 
           adminProfession, 
           adminWorkStatus ,
           adminPhone, 
           adminPassword,
           adminAccess
           )
           console.log('res',res)
            console.log('status',res.status)
          if (res.code == 0&&res.status==true) {
            console.log(res)
            // console.log('deptId', deptId)
            // console.log('de', deptId,
            //   email,
            //   nickname,
            //   password,
            //   phone,
            //   sex,
            //   loginName)
             this.$message.success('添加Admin成功')
            // 隐藏添加对话框
            this.dialogVisible = false
            // 重新获取Admin列表
            this.initArticleList()
         
          } else {
              this.$message.error(res.message)
          }
        } else {
         this.$message.error("工号格式错误")
          return false
        }
      })
    },
    // 展示编辑Admin的对话框
    showEditDialog (a) {
      //   const { data: res } = await this.$http.get('/system/sys_user/findSysUserById', { params: { id: id } })
      //   if (res.code !== 200) {
      //     this.$message.error('查询Admin失败')
      //   } else {
      //     // 保存到查询到的Admin信息对象
      //     this.editForm = res.data
      //     console.log(this.editForm)
      //   }
      //   // 展示
      // console.log('aaa', a.id)
      
      if(a.sex=0){
        a.sex='男'
      }
      else{
        a.sex='女'
      }
      this.editForm = a
      // console.log('11111111111111111111',a)
      this.editForm.adminId = a.adminId
      this.editDialogVisible = true
    },
    // 监听编辑Admin关闭对话框的事件
    editDialogClose () {
      this.updataUser = this.editForm
      console.log('this. edit',this.editForm)
      this.$refs.editFormRef.resetFields()
      this.initArticleList()
    },
    // 提交编辑Admin
    submitEditSysUser () {
      if(this.editForm.adminWorkStatus=='空闲'){
        this.editForm.adminWorkStatus=0;
      }
      else if(this.editForm.adminWorkStatus=='忙碌'){
        this.editForm.adminWorkStatus=1;
      }
      else if(this.editForm.adminWorkStatus=='离职'){
      this.editForm.adminWorkStatus=2;
      }
      else{
        this.editForm.adminWorkStatus=0;
      }
      if(this.editForm.adminProfession=='中心管理员'&&this.editForm.adminNum.charAt(0)==1){
        this.editForm.adminAccess=1
        this.is_trueEdit=true
      }
      else if(this.editForm.adminProfession=='初访员'&&this.editForm.adminNum.charAt(0)==2){
        this.editForm.adminAccess=2
        this.is_trueEdit=true
      }
      else if(this.editForm.adminProfession=='咨询师'&&this.editForm.adminNum.charAt(0)==3){
        this.editForm.adminAccess=3
        this.is_trueEdit=true
      }
      else if(this.editForm.adminProfession=='心理助理'&&this.editForm.adminNum.charAt(0)==4){
        this.editForm.adminAccess=4
        this.is_trueEdit=true
      }
      else{
        this.is_trueEdit=false
      }
      console.log(this.editForm.adminNum.charAt(0))
      console.log(this.editForm.adminProfession)
      console.log("44444444444",this.is_trueEdit)
      console.log(this.editForm.adminNum.charAt(0)==2)
      this.$refs.editFormRef.validate(async (valid) => {
        if (valid&&this.is_trueEdit) {
          // 发起真正的提交
        const { adminId,
        adminNum,
        adminName,
        adminAge,
        adminSex,
        adminAddress,
        adminProfession,
       adminWorkStatus,
       adminPhone,
       adminPassword,
       adminAccess} = this.editForm
          const { data: res } = await editAdmin(adminId,
        adminNum,
        adminName,
        adminAge,
        adminSex,
        adminAddress,
        adminProfession,
       adminWorkStatus,
       adminPhone,
       adminPassword,
       adminAccess)
          if (res.code == 0&&res.status==true) {
            // console.log(res)
            console.log('first', this.editForm)
                // 隐藏添加对话框
            this.editDialogVisible = false
            // // 重新获取Admin列表
            // console.log('last', this.editForm)
            this.getSysUserList()
            this.initArticleList()
            console.log('last', this.editForm)
            this.$message.success('修改Admin成功')
          
          } else {
          this.$message.error(res.message)
          }
        } else {
          this.$message.error('工号格式错误')
          return false
        }
      })
    },
    // 删除
    async removeSysUserById (adminId) {
      console.log('我是删除id', adminId)
      // 确认提示框
      const confirmResult = await this.$confirm('此操作将永久删除该Admin, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)
      // Admin确认删除，返回字符串 confirm
      // Admin取消删除，返回字符串 cancel
      if (confirmResult !== 'confirm') {
        this.$message.info('已取消删除')
      } else {
        // 确认删除
        const { data: res } = await deleteAdminByIdApI(adminId)
        console.log('123', res)
        if (res.code !== 0) {
          this.$message.error('删除Admin失败')
        } else {
          // 隐藏添加对话框
          this.editDialogVisible = false
          // 重新获取Admin列表
          this.$message.success('删除Admin成功')
          this.initArticleList()
        }
      }
    },
    ree (a) {
      // console.log(123123)
      // if (this.re) {
      //   this.editid = this.editid.filter((num) => {
      //     console.log('2222222', this.$refs.multipleTable.selection.id)
      //     return num !== this.$refs.multipleTable.selection.id
      //   })
      //   console.log('111111', this.editid)
      // }
    },

    toggleSelection (rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
      // console.log('22', val)
     },
    onTableSelect (rows, row) {
      console.log('1', rows, row)
      const selected = rows.length && rows.indexOf(row) !== -1
      console.log('se', selected)
    }, // true就是选中，0或者false是取消选中 } } }
    dropdown (a) {
      const arr = this.multipleSelection
      // console.log(this.editid)
      if (arr.length > 0) {
        arr.forEach((item) => {
          // console.log('b', item.id)
          this.editid.push(item.adminId)
        })
      } else {
        alert('请选择')
      }
      const uniqueArr = this.ids.filter((item, index) => {
        return this.ids.indexOf(item) === index
      })
      this.ids = uniqueArr
      // 0启用,1是冻结
      if (a.lable === '删除') {
        // console.log('1111', a.value)
        this.updateSysUser(this.editid, a.value)
           console.log('123321', this.editid)
        // console.log('321', this.editid)
        this.editid = []
      } else if (a.lable === '冻结') {
        // console.log(a.value)
        // this.updateSysUser(this.editid)
        // this.editid = []
        // console.log('冻结')
      }
    },
    async updateSysUser (ids) {
        console.log("22222222222",typeof(ids))
         console.log("111111111",[ids])
      const res = await deleteAdminsApI(ids)
   
        
      if (res.data.code === 0) {
        this.initArticleList()
        this.$message.success('修改成功')
      } else {
        this.$message.error('修改失败')
      }
    }
  }
  }

</script>

<style scoped>
.box-card {
  margin-top: 10px;
}
.el-table {
  margin-top: 10px;
}
.el-pagination {
  margin-top: 10px;
  margin-left: 470px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.dropdown {
  background: #409eff;
  opacity: 0.2;
}
.left{
  margin-left: 120px;
  width: 500px;
  height: 900px;
}
</style>
